﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;

namespace blackhouse.WebNemo.Web.Controls {
	public class FileEditRecordValue : EditRecordValue {

		#region Fields

		internal FileUpload fu;

		#endregion

		public override bool DisplayInline {
			get { return true; }
		}

		#region Methods

		protected override void CreateChildControls() {
			base.CreateChildControls();

			this.fu = new FileUpload();
			this.Controls.Add(this.fu);
		}

		protected override void PopulateControl() {
			this.EnsureChildControls();
		}

		public override void SaveInRecord() {
			if (fu.HasFile) {
				this.record.SetFileValue(this.column.ColumnName, fu.PostedFile.FileName.Split('\\').Last(), fu.PostedFile.InputStream);
			}
		}

		#endregion

	}
}